package com.crm.model.jdao;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import com.crm.model.pojo.Customer;
import com.crm.model.pojo.User;


/**
 * 客户DAO
 * @author Menghui
 *
 */
public interface ICustomerDAO extends CrudRepository<Customer, Integer>{


	/**
	 * 带条件分页，查询客户信息
	 * @param pageable
	 * @return
	 */
	 Page<Customer> findAll(Specification<Customer> spec,Pageable pageable);
	
	 /**
	  * 客户名称的模糊查询
	  * @param custName
	  * @return
	  */
	 @Query(value = "select * from customer  where cust_name like  CONCAT('%',:custName,'%') Limit 4",nativeQuery = true)
	 List<Customer> findByCustNameLike(@Param("custName") String custName);
	 
	 /**
	  * 根据客户名称查询
	  * @param custName
	  * @return
	  */
	 Customer findByCustName(String custName);
	 
	 /**
	  * 根据id查询客户
	  * @param custId
	  * @return
	  */
	 Customer findByCustId(Integer custId);
	 
	 //根据客户种类查询
	 List<Customer> findByCustType(Integer custType);
	 
	 //根据客户类型查询
	 List<Customer> findByCustSort(Integer custSort);
	 
	 //根据客户来源
	 List<Customer> findByCustSource(Integer custSource);
}
